import { createRouter, createWebHistory } from 'vue-router';
import Cart from '@/views/cart/cart.vue';
import Main from '@/views/main/Main.vue';
import Order from '@/views/order/order.vue'
import GetUserOrder from '@/views/order/getUserOrder.vue';
import Login from '@/views/user/Login.vue';
import Register from '@/views/user/Register.vue'; // 导入登录页面组件
import UserInfo from '@/views/user/UserInfo.vue'; // 导入用户信息页面组件



const routes = [
  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/main',
    name: 'main',
    component:  () => import('@/views/main/Main.vue')
  },
  {
    path: '/product/category/:categoryId',
    name: 'ProductList',
    component: () => import('@/views/category/ProductList.vue')
  },
  {
    path: '/product/:productId',
    name: 'ProductDetail',
    component: () => import('@/views/category/ProductDetail.vue')
  },
  {
    path: '/item/product/:productId',
    name: 'ItemList',
    component: () => import('@/views/category/ItemList.vue')
  },
  {
    path: '/item/:itemId',
    name: 'ItemDetail',
    component: () => import('@/views/category/ItemDetail.vue')
  },
  {
    path:'/search/:keyword',
    name:'ProductSearch',
    component: () => import('@/views/category/Search.vue')
  },
  {
    path: '/cartItem/user/:userId',
    name: 'Cart',
    component: Cart
  },
  {
    path: '/main',
    name: 'main',
    component: Main,
  },
  {
    path:'/order',
    name:'order',
    component: Order,
  },
  {
    path:'/order/getOrdersByUserId/:userId',
    name:'getUserOrder',
    component:GetUserOrder,
  },
  
  // 用户相关路由配置
{
  path: '/login',    // 登录页面路由
  name: 'Login',
  component: Login,
  meta: { requiresAuth: false }  // 不需要登录即可访问
},
{
  path: '/register', // 注册页面路由 
  name: 'Register',
  component: Register,
  meta: { requiresAuth: false }  // 不需要登录即可访问
},
{
  path: '/userinfo', // 用户信息页面路由
  name: 'UserInfo',
  component: UserInfo,
  meta: { requiresAuth: true }   // 需要登录才能访问
}

];

const router = createRouter({
    history: createWebHistory(),
    routes
  });

export default router;